#include<bits/stdc++.h>
using namespace std;
#define int long long 
typedef vector<int> ve;
typedef pair<int, int> pii;
// const int N;
const int inf = 0x3f3f3f3f;
////////////////////////////////////////////////////////
void gdb(const ve& x)
{
    for (auto& ch : x)
        cout << ch << " ";
    cout << endl;
}
int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}
//////////////////////////////////////////////////////////////

void slove()
{
    int cnt = 0;
    cin >> cnt;
    ve a;//模拟栈
    int botton = 0;
    while (cnt--) {
        int op = 0;
        cin >> op;
        if (op == 1)
        {
            int x; cin >> x;
            a.push_back(x);//尾插
        }
        else if (op == 2)
        {
            a.pop_back();//尾删
        }
        else if (op == 3)
        {
            cout << a.back() << endl;
        }
        else if (op == 4)
        {
            int k = 0; cin >> k;
            int ret = a.back();
            int n = a.size();
            for (int i = n - k; i < n - 1; i++)
            {
                ret = gcd(ret, a[i]);
                if (ret == 1)break;
            }
            for (int i = n - k; i < n; i++)
            {
                a[i] = ret;
            }
        }
    }
}

signed  main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int t = 1;
    // cin>>t;
    while (t--)
    {
        slove();
    }
    return 0;
}